/*
 * main.cpp
 *
 *  Created on: 2008-12-17
 *      Author: fanliangliang
 */

#include "toxic.h"
#include <iostream>
#include <cstring>

using namespace toxic;
using namespace std;

static void testBase64Encode(const string& str, const string& result) {
	Base64 base;
	if (base.encode(str) == result) {
		cout << "true:" << str << "->" << result << endl;
	}
	else {
		cout << "false:" << str << endl;
	}
}

static void testBase64Decode(const string& str, const string& result) {
	Base64 base;
	if (base.decode(str) == result) {
		cout << "true:" << str << "->" << result << endl;
	}
	else {
		cout << "false:" << str << endl;
	}
}

void do_test_base64() {

	cout << "***** base64 *****" << endl;

	const char myAlphabet[65] = {
		"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
	};

	Base64 base;
	base.setAlphabet(myAlphabet);
	base.printAlphabet();
	base.printReverseAlphabet();

	cout << "//Base64::encode" << endl;
	testBase64Encode("", "");
	testBase64Encode("f", "Zg==");
	testBase64Encode("fo","Zm8=");
	testBase64Encode("foo", "Zm9v");
	testBase64Encode("foob", "Zm9vYg==");
	testBase64Encode("fooba", "Zm9vYmE=");
	testBase64Encode("foobar", "Zm9vYmFy");

	cout << "\n//Base64:decode" << endl;
	testBase64Decode("", "");
	testBase64Decode("Zg==", "f");
	testBase64Decode("Zm8=", "fo");
	testBase64Decode("Zm9v", "foo");
	testBase64Decode("Zm9vYg==", "foob");
	testBase64Decode("Zm9vYmE=", "fooba");
	testBase64Decode("Zm9vYmFy", "foobar");
}
